<template>
	<view class="uiwu">
		<!-- <uiwu-nav-bar :list="navlist" @change="navChnage" /> -->
		<view class="uiwu-tabbar uiwu-flex-align">
			<view 
				class="item" 
				:class="tabActive == item.type ? 'active' : ''" 
				v-for="(item,index) in navlist" 
				:key="index"
				@tap="swiperTap(item)"
			>
				{{item.name}}
			</view>
		</view>
		<view class="uiwu-apply bank" v-if="formData.type == 'bank'">
			<view class="uiwu-apply-item">
				<text>银行卡号</text>
				<input type="text" v-model="formData.cardnum" placeholder="请输入银行卡号">
			</view>
			<view class="uiwu-apply-item">
				<text>真实姓名</text>
				<input type="text" v-model="formData.name" placeholder="请输入真实姓名">
			</view>
			<view class="uiwu-apply-item">
				<text>提现银行</text>
				<input type="text" v-model="formData.bankname" placeholder="请输入提现银行">
			</view>
		</view>
		<view class="uiwu-box">
			<view class="uiwu-box-top uiwu-flex">
				<view class="uiwu-box-top-left uiwu-flex">
					<text>￥</text>
					<input type="number" v-model="formData.money" placeholder="0.00" />
				</view>
				<view class="uiwu-box-top-right uiwu-flex-column">
					<text @tap.stop="allMoney">全部提现</text>
					<text>可提现余额：￥{{total_money}}</text>
				</view>	
			</view>
			<view class="uiwu-box-tips">
				<text>提示：{{shouxufen}}</text>
			</view>
		</view>
		
		<button class="uiwu-button uiwu-flex-center" @tap.stop="showModel = true">确认提现</button>
		<view class="uiwu-tips">
			<navigator url="record">提现记录</navigator>
		</view>
		<uiwu-popup-model v-model="showModel" @confirm="submit">
			是否确认提现？
		</uiwu-popup-model>
	</view>
</template>

<script lang="ts" setup>
	import { onLoad } from '@dcloudio/uni-app';
	import { ref } from "vue";
	import { cashextract , sysConfig } from "@/api/api";
	import { uiwu } from "../../config/config";
	const showModel = ref<boolean>(false)
	const tabActive = ref<string>('weixin')
	const total_money = ref<number|string>(0)
	const shouxufen = ref(0)
	const navlist = ref([{
		name:'微信零钱',
		type:'weixin'
	},{
		name:'银行卡',
		type:'bank'
	}])
	const formData = ref({
		extract_type:'weixin',
		money:null,
		name:'',
		bankname:'',
		cardnum:'',
	})
	const swiperTap = (item:object) => {
		tabActive.value = item.type
		formData.value.type = item.type
		formData.value.extract_type = item.type
	}
	/**
	 * 全部提现
	 */
	const allMoney = () => {
		formData.value.money = Number(total_money.value)
	}
	const submit = async () : Promise<any> => {
		if(!formData.value.money) return uiwu.toast('提现金额必须大于0')
		if(formData.value.extract_type == 'bank'){
			if(!formData.value.cardnum) return uiwu.toast('银行卡号不能为空')
			if(!formData.value.name) return uiwu.toast('持卡人姓名不能为空')
			if(!formData.value.bankname) return uiwu.toast('开户银行不能为空')
		}
		const reslut = await cashextract({
			...formData.value
		})
		if(!reslut) return
		uiwu.toast('提现成功')
	}		
	onLoad(async ({money})=>{
		const {data:{data}} = await sysConfig('cash_commission');
		shouxufen.value = data
		total_money.value = money
	})
</script>
<style lang="scss">
	page{
		background-color: #e6e6e6;
	}
	.uiwu{
		padding-top: 24rpx;
	}
	.uiwu-tabbar{
		width: 702rpx;
		margin: 0 auto;
		height: 100rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		.item{
			flex: 1;
			height: 100%;
			line-height: 100rpx;
			text-align: center;
			font-size: 32rpx;
			font-weight: 500;
			color: #666666;
			&.active{
				font-weight: bold;
				color: #231815;
				position: relative;
				&::after{
					content: "";
					position: absolute;
					left: 0;
					right: 0;
					bottom: 0;
					margin: 0 auto;
					width: 40rpx;
					height: 6rpx;
					background: #EF821E;
					border-radius: 5rpx;
				}
			}
		}
	}
	.uiwu-apply{
			margin: 24rpx auto 0;
			width: 702rpx;
			background: #FFF;
			border-radius: 20rpx;
			padding: 0 30rpx;
			&-item{
				display: flex;
				align-items: center;
				padding: 35rpx 0;
				text{
					font-size: 28rpx;
					font-weight: normal;
					color: #222222;
				}
				input{
					flex: 1;
					margin-left: 40rpx;
					font-size: 28rpx;
					color: #333;
				}
				image{
					width: 160rpx;
					height: 160rpx;
					border-radius: 10rpx;
				}
				&:last-child{
					align-items: flex-start;
					view{
						font-size: 28rpx;
						font-weight: normal;
						color: #222222;
						margin-top: 24rpx;
					}
				}
			}
		}
	.uiwu-box{
		margin: 24rpx auto 0;
		width: 702rpx;
		background: #FFF;
		border-radius: 20rpx;
		&-top{
			padding: 30rpx;
			border-bottom: 1rpx solid #DEDEDE;
			
			&-left{
				align-items: flex-end;
				text{
					font-size: 40rpx;
					font-weight: normal;
					color: #222222;
				}
				input{
					font-size: 50rpx;
				}
			}
			&-right{
				text-align: right;
				text{
					font-size: 26rpx;
					font-weight: normal;
					color: #888888;
					white-space: nowrap;
					&:nth-child(1){
						font-size: 32rpx;
						font-weight: bold;
						color: #FA5420;
						margin-bottom: 12rpx;
					}
				}
			}
		}
		&-tips{
			text-align: center;
			font-size: 24rpx;
			font-weight: normal;
			color: #888888;
			padding: 24rpx;
		}
	}
	.uiwu-button{
		width: 650rpx;
		height: 82rpx;
		background: #EF821E;
		border-radius: 41rpx;
		font-size: 32rpx;
		font-weight: bold;
		color: #FFFFFF;
		margin: 80rpx auto 0;
	}
	.uiwu-tips{
		font-size: 28rpx;
		font-weight: normal;
		color: #444444;
		text-align: center;
		padding: 30rpx;
	}
</style>
